package socket;
/** 客户端 */
import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) {
        Client client = new Client();
        client.start();
    }
    public void start(){
        //低级流
        try {
            OutputStream  os = socket.getOutputStream();
            PrintWriter pw= new PrintWriter(new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)),true);
            while (true){
                Scanner scan = new Scanner(System.in);
                String line = scan.nextLine();
                if("exit".equals(line)){
                    break;
                }
                pw.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();//与服务端断开连接
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    private Socket socket;
    public Client(){
        try{
            System.out.println("正在连接服务器");
            socket = new Socket("localhost",8200);
            System.out.println("与服务器建立连接");
            System.out.println("银色的世界");
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
